﻿using System;
using System.Data;
using eTMS.Controllers.CanBoLopService;
using System.Collections.Generic;
namespace eTMS.Controllers
{
    public class CanBoLopController : CanBoLopControllerBase
    {
        public CanBoLopController()
            : base()
        {
        }
        public void LoadAllDSCanBoLop(int Lop_ID)
        {
            Table = dao.SelectAllDSWithSinhVien(Lop_ID).Tables[0];
            AddIndexToTable();
            _tblRemoved = Table.Clone();
        }
        public void RemoveCanBoLop(List<DataRow> lsRemoved)
        {
            foreach (DataRow r in lsRemoved)
            {
                _tblRemoved.ImportRow(r);
                Table.Rows.Remove(r);
            }
            AddIndexToTable();
        }
        public void AddCanBoLop(List<DataRow> lsRow)
        {
            foreach (DataRow r in lsRow)
            {
                DataRow nr = Table.NewRow();
                foreach (DataColumn col in r.Table.Columns)
                {
                    if (Table.Columns.Contains(col.ColumnName))
                    {
                        nr[col.ColumnName] = r[col];
                    }
                }
                if (ChucVuCanBoLopController.ListChucVuCanBoLopStatic.Count > 0)
                    nr["ChucVuCanBoLop_ID"] = ChucVuCanBoLopController.ListChucVuCanBoLopStatic[0].ChucVuCanBoLop_ID;
                Table.Rows.Add(nr);
            }
            AddIndexToTable();
        }
        public void SaveCanBoLop()
        {
            foreach (DataRow r in _tblRemoved.Rows)
            {
                if (ConvertInt(r["CanBoLop_ID"]) > 0)
                {
                    dao.DeleteByID(ConvertInt(r["CanBoLop_ID"]));
                }
            }
            foreach (DataRow r in Table.Rows)
            {
                CanBoLopObject = MapDataRowToObject(r);
                if (CanBoLopObject.CanBoLop_ID > 0)
                {
                    Update();
                }
                else
                {
                    AddNew();
                }
            }
        }
        private DataTable _tblRemoved = new DataTable();
    }
}
